package mi.payment.utils.iso8583;

import mi.payment.constants.Configs;
import mi.payment.transaction.BaseQPSFreePwdAndSignController;
import mi.payment.settings.QPSParamsOperation;
import mi.payment.settings.QPSParamsSetting;
import sunmi.sunmiui.utils.LogUtil;

public class QPSFreePwdAndSign extends BaseQPSFreePwdAndSignController {

    /**
     * 盛付通双免判断流程：
     * 1.binA关闭、binB开启，判断binB表：binB卡小额挥卡消费，双免交易
     * 2.binA关闭、binB关闭，判断binC表（黑名单表）：非黑名单卡小额挥卡消费，双免交易
     */
    @Override
    public boolean isFreePassword(String strCardNo, String strAID, long saleAmount, String tag9F6C, String tag9F51, String tagDF71) {
        QPSParamsSetting qpsParamsSetting = QPSParamsOperation.getInstance().getQPSParamsSettings();
        boolean qpsParamCDCVMId = qpsParamsSetting.isQpsParamCDCVMId();
        boolean qpsParamNeedNoPswId = qpsParamsSetting.isQpsParamNeedNoPswId();
        boolean qpsParamBinAId = qpsParamsSetting.isQpsParamBinAId();
        boolean qpsParamBinBId = qpsParamsSetting.isQpsParamBinBId();
        boolean qpsParamBinCId = qpsParamsSetting.isQpsParamBinCId();
        long qpsParamNeedNoPswLimit = qpsParamsSetting.getQpsParamNeedNoPswLimit();

        LogUtil.e(Configs.TAG, "CD CVM标识:" + qpsParamCDCVMId);
        LogUtil.e(Configs.TAG, "非接快速业务标识:" + qpsParamNeedNoPswId);
        LogUtil.e(Configs.TAG, "BIN表A标识" + qpsParamBinAId);
        LogUtil.e(Configs.TAG, "BIN表B标识" + qpsParamBinBId);
        LogUtil.e(Configs.TAG, "BIN表C标识" + qpsParamBinCId);
        LogUtil.e(Configs.TAG, "免密限额:" + qpsParamNeedNoPswLimit);

        if (qpsParamNeedNoPswId) {
            boolean judge = isJudgeNeiOrWaiCard(tag9F51, tagDF71); // 判断内卡还是外卡 返回true——内卡 返回false——外卡
            if (judge) {
                if (qpsParamBinAId) {
                    return isUseCardBinA(strCardNo, saleAmount, qpsParamNeedNoPswLimit);
                } else {
                    if (qpsParamBinBId) {
                        return isUseCardBinB(strCardNo, strAID, saleAmount, qpsParamNeedNoPswLimit);
                    } else {
                        // 如果 BIN A和BIN B都关闭  则启动 BIN C（黑名单）
                        return isUseCardBinC(strCardNo, saleAmount, qpsParamNeedNoPswLimit);
                    }
                }
            } else {
                return isJudgeForeignCard(strAID, saleAmount, qpsParamNeedNoPswLimit, tag9F6C);
            }
        }
        return false;
    }


}